package com.x.erp.controller;

import java.io.IOException;
import java.util.List;


import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.LoanClue;
import com.x.erp.rpc.LoanClueRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;


/**
 * 贷款线索Controller
 * 
 * @author pansong
 *
 */
@RestController
@RequestMapping(value = "/loanClue")
public class LoanClueController extends BaseController {
	@Reference
	private LoanClueRpcService loanClueRpcService;// 贷款线索服务

	/**
	 * 新增贷款线索
	 * 
	 * @param loanClue
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/insertLoanClue", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel insertOrUpdateRotation(LoanClue loanClue) {
		if (loanClue == null) {
			return new ResultModel(ResultCode.RESULT_FAIL, "贷款线索信息不能为空！");
		}
		if(loanClue.getLoanType() == null){
			return new ResultModel(ResultCode.RESULT_FAIL, "贷款类型不能为空！");
		}
		// 每一条数据至少有一个字段有值（不包括id,marketId）
		if (loanClue.getModelId() == null && loanClue.getLoanAmount() == null 
				&& loanClue.getLoanPeriod() == null && loanClue.getLoanTime() == null 
				&& StringUtils.isBlank(loanClue.getLoanMortgage())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "插入失败！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！", loanClueRpcService.insertLoanClue(loanClue));
	}

	/**
	 * 获取贷款线索列表
	 * 
	 * @param loanClue
	 * @return
	 */
	@RequestMapping(value = "/getLoanClueList", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel selectLoanClueList(LoanClue loanClue) {
		List<LoanClue> list = loanClueRpcService.selectLoanClueList(loanClue);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", list);
	}
}
